define(
		[ "PDUtilDir/grid", "PDUtilDir/util", "PDUtilDir/tool",
				"PDUtilDir/slidebar", "PDUtilDir/inputSelect",
				"PDUtilDir/fileupload/singleFileUpload", "Date", "DateCN",
				"css!DateCss", "PicView", "css!picViewCss",
				"css!AppPathDir/relation/relationInfos/views/css/css" ],
		function(Grid, Util, Tool, Slidebar, inputSelect, MFU) {
			function addSupportInit($scope, $compile) {
				return new addSupport($scope, $compile);
			}
			function addSupport($scope, $compile) {
				var _this = this;
				this.re_search = {};
				this.cache = {};
				this.$scope = $scope;
				this.$compile = $compile;
			}
			addSupport.fn = addSupport.prototype;
			addSupport.fn.digest = function() {
				this.$scope.$digest();
			}
			addSupport.fn.run = function() {
				var _this = this, selectRows = _this.$scope.grid
						.getSelectedRow();
				if (selectRows.length == 0 || selectRows.length > 1) {
					Util.alert('请选择一条的数据！');
					return;
				}
				_this.cache.id = selectRows[0].deptUuid;
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/relation/relationInfos/views/add.html",
//					close : true,
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			addSupport.fn.initialization = function() {
				this.baseInit();
			};
			addSupport.fn.baseInit = function() {
				var _this = this;
				_this.cache.grid = Grid({
					id : "RelationOrgGirdDivId",
					pageSize : 10,
					index : true,
					multi : true,
					pagination : true,
					cache : false,
					layout : [
							{
								name : "机构名称",
								field : "deptName",
								sort : true
							},
							{
								name : "代码",
								field : "deptCode",
								sort : true
							},
							{
								name : "电话",
								field : "phone",
								width : "10%"
							},
							{
								name : "组织类型",
								field : "serviceType",
								format : function(e) {
									var serviceTypes = _this.$scope.cache.serviceTypes, len = serviceTypes.length;
									for (var i = 0; i < len; i++) {
										if (serviceTypes[i].dictCode == e.row.serviceType) {
											return serviceTypes[i].dictName;
										}
									}
								}
							}, {
								name : "状态",
								field : "deleted",
								format : function(e) {
									if (e.row.deleted == 0) {
										return "冻结";
									} else {
										return "正常";
									}
								}
							} ],
					toolbar : [ {
						name : "查询",
						icon : "fa fa-search",
						callback : function(event) {
							_this.cache.grid.reload({
								queryParam : _this.re_search
							})
						}
					} ],
//					data: [{"_checked":true, Name:"张三",Sex:"男",Phone:"123456",Email:"",Address:"BJ"},{Name:"张三",Sex:"男",Phone:"123456",Email:"",Address:"BJ"}]
					data : {
						type : "URL",
						value : getServer()
								+ "/flea/hclv/serviceOrg/queryAllServiceOrgPage.htmls",
					}
				});
				// 初始化类型下拉框
				inputSelect.dropCache();
				inputSelect({
					id : "re_serviceType",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.$scope.cache.serviceTypes,
					simpleData : true,
					searchAble : false,
					callback : function(id) {
						_this.re_search.serviceType = id[0];
					}
				});
				// 初始化省份下拉框
				inputSelect.dropCache();
				inputSelect({
					id : "re_queryProvince",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.$scope.cache.provinces,
					simpleData : true,
					// 启用文本搜索
					// initData:[initProvice],
					searchAble : false,
					callback : function(id) {
						var id = id[0];
						_this.re_search.queryProvince = id;
						_this.getCity(id);
					}
				});
			};
			addSupport.fn.getCity = function(pcode) {
				var _this = this;
				$.ajax({
					url : getServer() + "/flea/hclv/getCity.htmls",
					data : {
						'pcode' : pcode
					},
					success : function(data) {
						_this.cache.city = data.data;
						_this.init_queryCity();
					}
				});
			};
			// 初始化城市下拉框
			addSupport.fn.init_queryCity = function(pcode) {
				var _this = this;
				inputSelect.dropCache();
				inputSelect({
					id : "re_queryCity",
					key : {
						id : "dictCode",
						name : "dictName",
						data : "data",
					},
					data : _this.cache.city,
					simpleData : true,
					// 启用文本搜索
					// initData:[initProvice],
					searchAble : false,
					callback : function(id) {
						var id = id[0];
						_this.re_search.queryCity = id;
					}
				});
			};

			addSupport.fn.save = function() {
				var _this = this, selectRows = _this.cache.grid
						.getSelectedRow();
				if (selectRows.length == 0) {
					Util.alert('请选择至少一条数据！');
					return;
				}
				var ids = new Array();
				$.each(selectRows, function(index, selectRow) {
					ids.push(selectRow.deptUuid);
				});
				$.ajax({
					url : getServer() + "/flea/hclv/product/save.htmls",
					data : {
						'model' : JSON.stringify({
							deptUuid : _this.cache.id,
							ids : ids
						})
					},
					success : function(data) {
						Util.alert('成功');
						_this.slidebars.close();
					}
				});
			};
			return addSupportInit;
		});